﻿@model MessageTemplateModel

@using Telerik.Web.Mvc.UI;
@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)
@Html.Telerik().TabStrip().Name("template-edit").Items(x =>
{
    x.Add().Text(T("Admin.ContentManagement.MessageTemplates.Info").Text).Content(TabInfo().ToHtmlString()).Selected(true);
    x.Add().Text(T("Admin.ContentManagement.MessageTemplates.Stores").Text).Content(TabStores().ToHtmlString());

    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new AdminTabStripCreated(x, "template-edit"));
})
@helper TabInfo()
{
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AllowedTokens):
            </td>
            <td class="adminData">
                @Html.DisplayFor(model => model.AllowedTokens)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Name):
            </td>
            <td class="adminData">
                @Model.Name
                @Html.HiddenFor(model => model.Name)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.IsActive):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.IsActive)
                @Html.ValidationMessageFor(model => model.IsActive)
            </td>
        </tr>
    </table>
    @(Html.LocalizedEditor<MessageTemplateModel, MessageTemplateLocalizedModel>("messagetemplate-localized",
    @<table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].BccEmailAddresses):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => Model.Locales[item].BccEmailAddresses)
                @Html.ValidationMessageFor(model => model.Locales[item].BccEmailAddresses)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].Subject):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => Model.Locales[item].Subject)
                @Html.ValidationMessageFor(model => model.Locales[item].Subject)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].Body):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => Model.Locales[item].Body, "RichEditor")
                @Html.ValidationMessageFor(model => model.Locales[item].Body)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Locales[item].EmailAccountId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => Model.Locales[item].EmailAccountId, new SelectList(Model.AvailableEmailAccounts, "Id", "DisplayName", Model.Locales[item].EmailAccountId))
                @Html.ValidationMessageFor(model => model.Locales[item].EmailAccountId)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                @Html.HiddenFor(model => model.Locales[item].LanguageId)
            </td>
        </tr>
    </table>
    ,
    @<table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.BccEmailAddresses):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.BccEmailAddresses)
                @Html.ValidationMessageFor(model => model.BccEmailAddresses)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Subject):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Subject)
                @Html.ValidationMessageFor(model => model.Subject)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Body):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Body, "RichEditor")
                @Html.ValidationMessageFor(model => model.Body)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.EmailAccountId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.EmailAccountId, new SelectList(Model.AvailableEmailAccounts, "Id", "DisplayName"))
                @Html.ValidationMessageFor(model => model.EmailAccountId)
            </td>
        </tr>
    </table>
    ))


}

@helper TabStores()
{
    <script type="text/javascript">
        $(document).ready(function () {

            $("#@Html.FieldIdFor(model => model.LimitedToStores)").click(toggleStoreMapping);

            toggleStoreMapping();
        });


        function toggleStoreMapping() {
            if ($('#@Html.FieldIdFor(model => model.LimitedToStores)').is(':checked')) {
                $('#pnl-available-stores').show();
            }
            else {
                $('#pnl-available-stores').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LimitedToStores):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitedToStores)
                @Html.ValidationMessageFor(model => model.LimitedToStores)
            </td>
        </tr>
        <tr id="pnl-available-stores">
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AvailableStores):
            </td>
            <td class="adminData">
                @if (Model.AvailableStores != null && Model.AvailableStores.Count > 0)
                {
                    foreach (var store in Model.AvailableStores)
                    {
                    <div>
                        <input type="checkbox" name="SelectedStoreIds" value="@store.Id" checked="@(Model.SelectedStoreIds != null && Model.SelectedStoreIds.Contains(store.Id))" />@store.Name
                    </div>
                    }
                }
                else
                {
                    <div>No stores defined</div>
                }</td>
        </tr>
    </table>
}

